package CtrlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class CustomerController{
    private CustomerContainer customerContainer;

    public CustomerController(){
        customerContainer = CustomerContainer.getInstance();
    }

    public void createCustomerObjects(){  
        customerContainer.addCustomer(new Customer(1000,"James", "ddd@dd.dd", "1111111111", "Ravnkildevej 1", 20));
        customerContainer.addCustomer(new Customer(1001, "Stephan", "ddd@dd.dd", "22222222", "Ravnkildevej 2", 15));
        customerContainer.addCustomer(new Customer(1002, "Esteban", "ddd@dd.dd", "33333333", "Ravnkildevej 3", 10));
    }

    public boolean createCustomer(int id, String name, String email,String phoneNumber, String address, int discount){
        boolean added = false;
        if(findCustomer(id) == null) {
            customerContainer.addCustomer(new Customer(id, name, email, phoneNumber, address, discount));
            added = true;
        } else {
            added = false;
        }
        return added;
    }

    public Customer findCustomer(int id){    
        return  customerContainer.findCustomerById(id);
    }

    public boolean deleteCustomer(int id){
       customerContainer.deleteCustomer(customerContainer.findCustomerById(id));
       boolean flag = true;
       try{
           findCustomer(id);
           flag = false;
        }catch(Exception e){}
        return flag;
    }

    public void updateCustomer(int id, String name, String email,String phoneNumber, String address, int discount){
        Customer c =  customerContainer.findCustomerById(id);
        if(c != null){
            c.setName(name);
            c.setEmail(email);
            c.setPhoneNumber(phoneNumber);
            c.setAddress(address);
            c.setDiscount(discount);
        }
    }
}
